#include <event2/event.h>
void read_cb(evutil_socket_t, short, void* );
void write_cb(evutil_socket_t, short, void* );
void main_loop(evutil_socket_t fd)
{
    struct event* important, * unimportant;
    struct event_base* base;
    struct timeval five_seconds = {5,0};
    base = event_base_new();
    event_base_priority_init(base, 2);
    /* Now base has priority 0, and priority 1 */
    important = event_new(base, fd, EV_WRITE|EV_PERSIST, write_cb, NULL);
    unimportant = event_new(base, fd, EV_READ|EV_PERSIST, read_cb, NULL);
    event_priority_set(important, 0);
    event_priority_set(unimportant, 1);
    /* Now, whenever the fd is ready for writing, the write callback will
    happen before the read callback. The read callback won’t happen at
    all until the write callback is no longer active.
    */
   event_add(important, &five_seconds);
    event_add(important, NULL);
   event_base_dispatch(base);
}
int main()
{
    main_loop(fileno(stdin));
    return 0;
}
void read_cb(evutil_socket_t fd, short what, void* arg)
{
    const char* data = arg;
    printf("Got an event on socket %d:%s%s%s%s [%s]\n",
        (int) fd,
        (what&EV_TIMEOUT) ? " timeout" : "",
        (what&EV_READ) ? " read" : "",
        (what&EV_WRITE) ? " write" : "",
        (what&EV_SIGNAL) ? " signal" : "",
        data);
}
void write_cb(evutil_socket_t fd, short what, void* arg)
{
    read_cb(fd, what, arg);
}